$(function(){
    listarAnio('ddanio','Todos');
    
    $("#btnBuscarMultaDetalle").click(function(){
        
        buscar();
    });
});

var buscar = function() {
    if(ValidarRequeridos()){
        var vid_multa = $("#txtMultaDetalSearch").val();
        var vanio = $("#ddanio").val();
        var vurli='ajax/ajaxCUM.php?opc=bus1&nd='+new Date().getTime()+'&id_multa='+vid_multa+'&vanio='+vanio;
    
        var cum = {
            opc:"bus1",
            id_multa: $("#txtMultaDetalSearch").val(),
            anio: $("#ddanio").val()
        };
        $("#grid").jqGrid("clearGridData", true);
        $("#grid").jqGrid('setGridParam',{url:vurli,datatype:'json',mtype: 'POST',postData:cum}).trigger('reloadGrid');
    
        jQuery("#grid").jqGrid({
            url:vurli,
            datatype: "json",
            mtype: 'POST',
            postData:cum,
            colNames: ['Codigo','Multa', 'Codigo Estado','Estado','Nro. Resolucion','Fec. Resolucion','Siglas','A&#241;o'],
            colModel: [
                        {name: 'ID_MULTA_DETAL',index: 'ID_MULTA_DETAL',width: 100,sorttype:"string"},
                        {name: 'ID_MULTA',index: 'ID_MULTA',width: 100,sorttype:"string"},
                        {name: 'ESTADO_MULTA',index: 'ESTADO_MULTA',width: 100,sorttype:"string",hidden:true},
                        {name: 'ESTADO',index: 'ESTADO',width: 100,sorttype:"string"},
                        {name: 'NRO_RESOLUCION',index: 'NRO_RESOLUCION',width: 100,sorttype:"string"},
                        {name: 'FEC_RESOLUCION',index: 'FEC_RESOLUCION',width: 100,sorttype:"string"},
                        {name: 'DES_SIGLA',index: 'DES_SIGLA',width: 100,sorttype:"string"},
                        {name: 'ANIO_RESOLUCION',index: 'ANIO_RESOLUCION',width: 100,sorttype:"string"}
                      ],
            rowNum:10,
            rowList:[10,20,30],
            pager: '#pager',
            sortname: 'id',
            viewrecords: true,
            sortorder: "desc",
            multiselect: true,
            multiSort:true,
            width: "800",
            height: "220",
            caption: "Detalle de Multas"
        }).navGrid("#pager", {
            edit: false,
            add: false,
            search: false,
            del: false
        });
    }
};

jQuery.extend(jQuery.jgrid.edit, {
    ajaxEditOptions: { contentType: "application/json" },
    recreateForm: true,
    serializeEditData: function (postData) {
        return JSON.stringify(postData);
    }
});

jQuery.extend(jQuery.jgrid.del, {
    ajaxDelOptions: { contentType: "application/json" },
    serializeDelData: function (postData) {
        return JSON.stringify(postData);
    }
});